package com.huike.clues.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.huike.clues.domain.SysDictType;
import com.huike.clues.domain.dto.SysDictTypeQueryDTO;
import com.huike.clues.domain.vo.SysDictTypeVo;
import com.huike.clues.mapper.SysDictTypeMapper;
import com.huike.clues.service.ISysDictTypeService;

import com.huike.common.core.domain.entity.SysDictTypeDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.annotation.AccessType;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

@Service
public class SysDictTypeServiceImpl extends ServiceImpl<SysDictTypeMapper,SysDictType> implements ISysDictTypeService {
    @Autowired
    private SysDictTypeMapper sysDictTypeMapper;
    /**
     * 字典类型分页条件查询
     *
     * @param dto
     * @return
     */
    @Override
    public SysDictTypeVo pageQuery(SysDictTypeQueryDTO dto) {
        IPage<SysDictType> p=new Page<SysDictType>(dto.getPageNum(),dto.getPageSize());
        LocalDate l1 = null;
        LocalDate l2 = null;
        if (dto.getParams()!=null) {
            l1 = (dto.getParams().get("beginTime"));
            l2 = (dto.getParams().get("endTime"));
        }
        IPage<SysDictType> resultPage = this.page(p,
                Wrappers.<SysDictType>lambdaQuery().like(dto.getDictName()!=null,SysDictType::getDictName,dto.getDictName())
                        .like(dto.getDictType()!=null,SysDictType::getDictType,dto.getDictType()).eq(dto.getStatus()!=null,SysDictType::getStatus,dto.getStatus())
                        .between(l1!=null&&l2!=null,SysDictType::getCreateTime,l1,l2));
        SysDictTypeVo s = new SysDictTypeVo();
        s.setRows(resultPage.getRecords());
        s.setParams(dto.getParams());
        s.setTotal(resultPage.getTotal());
        return s;
    }
}
